package com.wlxt.springcloud.member.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wlxt.springcloud.member.client.BookResultDTO;
import com.wlxt.springcloud.member.client.BookServiceClient;
import com.wlxt.springcloud.member.constant.Constants;
import com.wlxt.springcloud.member.entity.Member;
import com.wlxt.springcloud.member.exception.BookNotFoundException;
import com.wlxt.springcloud.member.exception.MemberNotFoundException;
import com.wlxt.springcloud.member.service.MemberService;
@Service
public class MemberServiceImpl implements MemberService {
	@Autowired
	private BookServiceClient bookServiceClient;
	@Override
	public Member checkByMobile(String mobile) {
		Member member = Constants.MEMBER_MAP.get(mobile);
		if(member == null) {
			throw new MemberNotFoundException("会员不存在");
		}
		return member;
	}

	@Override
	public String getInfo(String bid) {
		BookResultDTO restResult = bookServiceClient.getInfo(bid);
		if(restResult == null || restResult.getData() == null) {
			throw new BookNotFoundException("图书微服务不可用!");
		}
		return restResult.getData().getName();
	}

}
